/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import game.webClient.Currency;
import game.webClient.CurrencyConvertor;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.xml.ws.WebServiceRef;

/**
 *
 * @author Light
 */
@ManagedBean(name = "CurrencyConverter")
@RequestScoped
public class CurrencyConverter {

    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/www.webservicex.net/CurrencyConvertor.asmx.wsdl")
    private CurrencyConvertor service;
    List<String> curr = null;
    String from = "EUR";
    String to = "USD";
    double rate = 0;

    public List<String> getCurr() {
        curr = new ArrayList<String>();

        for (Currency cur : Currency.values()) {
            curr.add(cur.toString());
        }

        return curr;
    }

    public void setCurr(List<String> curr) {
        this.curr = curr;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public double getRate() {

        try { // Call Web Service Operation
            game.webClient.CurrencyConvertorSoap port = service.getCurrencyConvertorSoap();
            // TODO initialize WS operation arguments here
            game.webClient.Currency fromCurrency = game.webClient.Currency.fromValue(from);
            game.webClient.Currency toCurrency = game.webClient.Currency.fromValue(to);
            // TODO process result here
            double result = port.conversionRate(fromCurrency, toCurrency);
            rate = result;
            System.out.println("Result = " + result);
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

        return rate;
    }

    public void setRate(int rate) {
        this.rate = rate;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    /** Creates a new instance of FormValidator */
    public CurrencyConverter() {
    }
}
